package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.OrganizationWalletConfigDao;
import com.bestcem.xm.user.dao.mapper.OrganizationWalletConfigMapper;
import com.bestcem.xm.user.entity.mysql.OrganizationWalletConfig;
import com.bestcem.xm.user.entity.pojo.OrganizationWalletConfigDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.OrganizationWalletConfigConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公司钱包配置dao实现
 *
 * @author wangyunyun <yunyun.wang@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/13 10:34
 */
@Repository
public class OrganizationWalletConfigDaoImpl implements OrganizationWalletConfigDao {

    @Resource
    private OrganizationWalletConfigConvert organizationWalletConfigConvert;

    @Resource
    private OrganizationWalletConfigMapper organizationWalletConfigMapper;

    @Override
    public String insert(OrganizationWalletConfigDO organizationWalletConfigDO) {
        // 设置参数
        OrganizationWalletConfig organizationWalletConfig = organizationWalletConfigConvert.do2Mysql(organizationWalletConfigDO);
        organizationWalletConfig.setWalletConfigId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(organizationWalletConfig);
        // 新增
        organizationWalletConfigMapper.insertSelective(organizationWalletConfig);
        // 设置返回值
        return organizationWalletConfig.getWalletConfigId();
    }

    @Override
    public Integer updateByCondition(OrganizationWalletConfigDO param, OrganizationWalletConfigDO condition) {
        // 设置更新参数
        OrganizationWalletConfig organizationWalletConfig = organizationWalletConfigConvert.do2Mysql(param);
        DataBaseUtil.setUpdateTime(organizationWalletConfig);
        // 更新
        return organizationWalletConfigMapper.updateByCondition(organizationWalletConfig, organizationWalletConfigConvert.do2Mysql(condition));
    }

    @Override
    public List<OrganizationWalletConfigDO> selectBySelective(OrganizationWalletConfigDO organizationWalletConfigDO, List<String> orgIds) {
        return organizationWalletConfigConvert.mysqls2Dos(
                organizationWalletConfigMapper.selectBySelective(organizationWalletConfigConvert.do2Mysql(organizationWalletConfigDO), orgIds));
    }

    @Override
    public Integer insertBatch(List<OrganizationWalletConfigDO> walletConfigDOList) {
        return organizationWalletConfigMapper.insertBatch(organizationWalletConfigConvert.dos2Mysqls(walletConfigDOList));
    }
}
